<template>
  <div class="footer">
    <div v-for="(item, index) in footerIcon" class="footer-icon" @click="hanldeGo(item.url)">
      <span :class="[`iconfont icon-${item.icon}`]" />
      <span class="footer-notice" v-if="item.notice?.length">{{ item.notice.length }}</span>
      <span>{{ item.name }}</span>
    </div>
  </div>
</template>

<script lang="ts" setup>
import router from '@/router';
import { getFriendNotice } from "@/api/user/index"
import { userStore } from '@/store/user'
import { reactive, ref } from "vue"

const user_store = userStore()
// 获取好友请求
getFriendNotice().then((res: any) => {
  user_store.changeUserNotice(res)
  if (res.data.data.length) {
    footerIcon.forEach((item, index) => {
      if (item.icon === 'friend') {
        item.notice = res.data.data
      }
    })
  }
})

const footerIcon = reactive([
  { icon: 'home', name: '首页', url: '/main' },
  { icon: 'friend', name: '好友', url: '/friends', notice: [] },
  { icon: 'add', url: '/addArticle' },
  { icon: 'notice', name: '通知', url: '' },
  { icon: 'meh', name: '我的', url: '' }
])
const hanldeGo = (url: string) => {
  router.push(url)
}
</script>

<style scoped lang="less">
.footer {
  position: fixed;
  bottom: 0;
  display: flex;
  width: 100%;
  height: 120px;
  justify-content: space-around;
  align-items: center;
  background-color: #ffffff;
  padding-bottom: 20px;

  &-icon {
    position: relative;
    height: 100%;
    width: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    &:nth-child(3) {
      height: 150px;
      width: 150px;
      border-radius: 50%;
      background-color: #ffffff;

      >span {
        display: flex;
        align-items: center;
        justify-content: center;

        &:hover {
          color: #222222;
        }

        &:first-child {
          width: 110px;
          height: 110px;
          border-radius: 50%;
          background-color: #fde890;
        }
      }
    }

    &:hover {
      color: #07d88e;
    }

    >span {
      &:first-child {
        font-size: 50px;
        font-size: 50px;
      }
    }
  }

  &-notice {
    position: absolute;
    top: 10px;
    right: 0;
    background-color: red;
    padding: 2px 15px;
    border-radius: 50%;

    &:hover {
      color: #222222;
    }
  }
}
</style>